package com.xxc.response.result

import com.xxc.common.anotation.POKO
import com.xxc.common.enums.ResultCode
import com.xxc.common.util.json.gson.GsonUtil

/**
 * 通用响应
 * @param code 响应码
 * @param msg 响应消息
 * @param data 响应数据
 */
@POKO
data class PlatformResult<T> (var code:Int = 200,var msg:String? = "",var data:T? = null):Result{

    constructor(resultCode: ResultCode,data:T? = null) : this(resultCode.code(),resultCode.message(),data)

    companion object{
        fun <B> success(body:B):PlatformResult<B>{
            return PlatformResult(ResultCode.SUCCESS.code(),ResultCode.SUCCESS.message(),body)
        }

        fun failure(resultCode: ResultCode, obj:Any): PlatformResult<*> {
            return PlatformResult(resultCode,obj)
        }

    }
}